<script lang='ts' setup>
import { ref, watch } from 'vue';
import MonacoEditor from "@/components/MonacoEditor/index.vue"
const props = defineProps<{
    'value': string,
    'show': boolean,
    'index': number,
}>()
const emits = defineEmits<{
    (e: 'close',): void,
    (e: 'onChange', val: string): void,
}>()
const scriptValue = ref(props.value)
const showSelf = ref(props.show)
watch(() => props.show, (val: any) => {
    showSelf.value = val;
    if (val) {
        scriptValue.value = props.value
    }
}, { immediate: true })
function close() {
    emits('close',)
}
function save() {
    emits('onChange', scriptValue.value)
}
</script>
<template>
    <el-dialog v-model="showSelf" destroy-on-close :title="index == 0 ? '编辑前置脚本' : index == 1 ? '编辑后置脚本':'编辑脚本'" width="1000px"
        @close="close">
        <monaco-editor v-model="scriptValue" language="java" style="height:350px"></monaco-editor>
        <template #footer>
            <el-button @click="close">取消</el-button>
            <el-button @click="save" type="primary">保存</el-button>
        </template>
    </el-dialog>
</template>
<style scoped lang='scss'></style>